package com.pay.ioopos.activity;

import android.content.Intent;
import android.os.Bundle;

import com.pay.ioopos.KeyInfo;
import com.pay.ioopos.R;
import com.pay.ioopos.StatusListener;
import com.pay.ioopos.fragment.PasswordFragment;
import com.pay.ioopos.fragment.TipVerticalFragment;

import static com.pay.ioopos.KeyInfo.KEY_CANCEL;
import static com.pay.ioopos.KeyInfo.KEY_ENTER;
import static com.pay.ioopos.fragment.TipFragment.TipType.SUCCESS;

public class PasswordActivity extends AbstractActivity implements StatusListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_password);
        PasswordFragment fragment = new PasswordFragment(this);
        setMainFragment(fragment);
    }

    @Override
    public boolean onKeyDown(KeyInfo keyInfo) {
        if (mainFragment instanceof PasswordFragment) {
            PasswordFragment fragment = ((PasswordFragment)mainFragment);
            fragment.onKeyDown(keyInfo);
        } else {
            if (keyInfo == KEY_ENTER) {
                Intent intent = new Intent(this, SystemActivity.class);
                startActivity(intent);
            }
        }
        if (keyInfo == KEY_CANCEL) {
            Intent intent = new Intent(this, SystemActivity.class);
            startActivity(intent);
        }
        return false;
    }

    @Override
    public void onSuccess(String msg) {
        setMainFragment(new TipVerticalFragment(SUCCESS, msg));
    }

}
